package org.ethan.lyl;

import org.ethan.lyl.util.Path;
import org.springframework.boot.SpringApplication;

import java.io.File;
import java.io.IOException;
import java.util.Date;

/**
 * @Author:Eason Lau
 * @Date:2018/10/29
 * @Description: 手机截图
 */
public class Screenshot {


    public static void main(String[] args) {

    }

    /**
     * 获取屏幕截图
     * @return
     */
    public static String screenshotByADB(){
        /*String path = Path.SysPath();
        File adbDir = new File(path+ "adb");
        //获取class文件根目录
        String classPath = Screenshot.class.getResource("/").getPath().substring(1);*/
        //检测截屏文件存储文件是否存在，不存在则创建
        File f = new File(Path.SysPath() + "/screenshot");
        if(!f.exists())
        {
            f.mkdir();
        }
        Runtime rt = Runtime.getRuntime();
        Process p = null;
        try {
            String fileName = "screenshot.png";
            //截屏
            p = rt.exec("cmd.exe /c "+Path.SysPath()+"adb\\adb shell /system/bin/screencap -p /sdcard/"+fileName);
            p.waitFor();
            //拉取截屏图片
            p = rt.exec("cmd.exe /c "+Path.SysPath()+"adb\\adb pull /sdcard/"+fileName +" "+f+"/"+fileName);
            p.waitFor();
            return f+"/"+fileName;
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return null;

    }
}
